-module(mnesia_op).
-include("agent.hrl").
-export([add_agent_state_item/3, add_app_item/4,remove_app_item/1, remove_all_app_item/0]).

add_agent_state_item(Pid,Cpu,Container) ->
	mnesia:clear_table(agent_state).
	Row = #agent_state{ pid = Pid, cpu = Cpu, container = Container},
	F = fun() ->
		mnesia:write(Row)
	    end,
	mnesia:transaction(F).


add_app_item(Name, Domain, Source, Target) ->
	Row = #app{ name = Name, domain = Domain, source = Source, target = Target},
	F = fun() ->
		mnesia:write(Row)
	    end,
	mnesia:transaction(F).

remove_app_item(Name) ->
	Oid = {app, Name},
	F = fun() ->
		mnesia:delete(Oid)
	    end,
	    mnesia:transaction(F).
	  
remove_all_app_item() ->
	F = fun() ->
		mnesia:clear_table(app)
	    end,
	    mnesia:transaction(F).
